{% extends 'base.html' %}

{%block login%}
<ul class="nav navbar-nav navbar-right">
<li><a href="/MLWebService/logout">登出</a></li>
</ul>
{%endblock%}

{% block content %}
    <h2>机器学习训练任务管理</h2>
        <table class="table" id='oTabel'>
            <caption>测试结果</caption>
            <br>
            <tbody>
                {% for result in data %}
                    <tr>
                        {%for fea in result%}
                        <td>{{fea}}</td>
                        {% endfor%}
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        <button class="btn btn-default" id = "download">下载测试结果</button>
<script>
    $("#download").on("click", function() {
        console.log("miaomiaomiao?")
        var result = ""
        $("#oTabel tr").each(function (key, value) {
            $(this).find("td").each(function (key, value) {
                result+=$(this).html()
                result+=","
            });
            result+="\n"
        //arr.push($(this).html());
        });
        var urlObject = window.URL || window.webkitURL || window;
　　　   var export_blob = new Blob(["\ufeff" +result]);
　　　　 var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
　　　　 save_link.href = urlObject.createObjectURL(export_blob);
　　　　 save_link.download = "test.csv";
　　　　 fakeClick(save_link);

        console.log(result)
        //console.log(trl.length) 

            
        //window.location.href = 'data:text/csv;charset=UTF-8,\ufeff'
            //+ encodeURIComponent(csv);
    });
    function fakeClick(obj) { 
        　　var ev = document.createEvent("MouseEvents");
    　　　　ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    　　　　obj.dispatchEvent(ev);
    　　};
</script>
{% endblock %}